<?php
class Rese_model extends CI_Model{
	function __construct(){
		parent::__construct();
	}

	public function action($pid,$type){
		
		$data['type'] = $type;
		$data['pid'] = $pid;
		$data['content'] = addslashes(htmlspecialchars($this->form_validation->set_value('content')));
		$data['time'] = $this->form_validation->set_value('time') ? $this->form_validation->set_value('time') : date('Y-m-d H:i:s');
		if($this->db->insert('rese',$data)){
			return array('status'=>true);
		}else{
			return array('status'=>false,'msg'=>'添加失败，可能网络出错！');
		}
	}
	
	public function update($pid,$type){
		
		$data['content'] = addslashes(htmlspecialchars($this->form_validation->set_value('content')));
		$data['time'] = $this->form_validation->set_value('time') ? $this->form_validation->set_value('time') : date('Y-m-d H:i:s');
		$this->db->where('pid',$pid);
		$this->db->where('type',$type);
		if($this->db->update('rese',$data)){
			return array('status'=>true);
		}else{
			return array('status'=>false,'msg'=>'添加失败，可能网络出错！');
		}
	}


	public function get_rese_bytype($pid,$type){
		
		$this->db->where('pid',$pid);
		$this->db->where('type',$type);

		$query = $this->db->get('rese');
		if($query->num_rows){
			return $query->row();
		} else {return false;}
	}

	public function get_rese_bypid($pid){
		$this->db->where('pid',$pid);
		$query = $this->db->get('rese');
		if($query->num_rows){
			return $query->result();
		} else {return false;}
	
	}


}